package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"time"
)

const Authorization = "Bearer 15CDF826BAD94B8DB114D0FBC31BAE71"

func main() {
	//newApi("http://localhost:8080/permission-plus/function/perp/gatewayTestB", gatewayTestBody())
	//newApi("http://bfs-api-gateway.bfs.qa.yunlizhi.net/permission-plus/function/perp/gatewayTestB", gatewayTestBody())
	//newApi("http://bfs-user-web.bfs.qa.yunlizhi.net/permission-plus/function/perp/gatewayTestB", gatewayTestBody())

}

func gatewayTestBody() *bytes.Buffer {
	requestBody := map[string]interface{}{}
	jsonBody, err := json.Marshal(requestBody)
	if err != nil {
		fmt.Println("请求体转换为JSON失败:", err)
		return nil
	}
	return bytes.NewBuffer(jsonBody)
}

func newApi(url string, requestBodyBuffer *bytes.Buffer) {
	start := time.Now()
	req, err := http.NewRequest("POST", url, requestBodyBuffer)
	req.Header.Add("Content-Type", "application/json")
	req.Header.Add("Authorization", Authorization)

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println("请求发送失败:", err)
		return
	}
	defer resp.Body.Close()
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("读取响应失败:", err)
		return
	}
	duration := time.Since(start).Milliseconds()
	fmt.Println(url+",请求执行时间:", duration)
	fmt.Println("恢复内容:", string(body))
	fmt.Println("------------------------------------------------------------------")

}
